package com.lmaor.project.commons.parameters;

import java.lang.annotation.Annotation;

public class ParameterAnnotations {
	ParameterAnnotation annss[] = null;
	public ParameterAnnotations(Annotation[][] annotations) {
		annss = new ParameterAnnotation[annotations.length];
		for (int i = 0; i < annotations.length; i++) {
			Annotation[] paramAnns = annotations[i];
			ParameterAnnotation anns = annss[i] = new ParameterAnnotation();
			if(paramAnns!=null&&paramAnns.length>0){
				for (Annotation paramAnn : paramAnns) {
					anns.put(paramAnn.annotationType(), paramAnn);
				}
			}
		}
	}
	public ParameterAnnotation getParameterAnnotation(int index){
		if(index >= annss.length){
			return null;
		}
		return annss[index];
	}
	public <T extends Annotation>T getParameterAnnotation(int index,Class<T> anntype){
		ParameterAnnotation parameterAnnotation = getParameterAnnotation(index);
		T annt= null;
		if(parameterAnnotation != null){
			Annotation annotation = parameterAnnotation.get(anntype);
			if(annotation!=null){
				annt = (T) annotation;
			}
		}
		return annt;
	}
}
